package com.diboot.core.methods;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

import com.diboot.core.methods.RecycleBinSqlMethod;
import org.apache.ibatis.scripting.defaults.RawSqlSource;

public class GetOneInRecycleBin extends AbstractMethod {
    public GetOneInRecycleBin() {
        this(RecycleBinSqlMethod.SELECT_BY_ID.name());
    }

    public GetOneInRecycleBin(String name) {
        super(name);
    }
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        RecycleBinSqlMethod sqlMethod = RecycleBinSqlMethod.SELECT_BY_ID;
        SqlSource sqlSource = new RawSqlSource(this.configuration, String.format(sqlMethod.getSql(), this.sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(), tableInfo.getKeyProperty(), " AND NOT (" + tableInfo.getLogicDeleteSql(true, true) + ") "), Object.class);
        return this.addSelectMappedStatementForTable(mapperClass, this.methodName, sqlSource, tableInfo);
    }
}
